package com.ruoyi.project.order.info.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.order.info.mapper.OrderInfoMapper;
import com.ruoyi.project.order.info.domain.OrderInfo;
import com.ruoyi.project.order.info.service.IOrderInfoService;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.system.info.mapper.RoomInfoMapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单信息Service业务层处理
 * 
 * @author yyj
 * @date 2021-05-13
 */
@Service
public class OrderInfoServiceImpl implements IOrderInfoService 
{
    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private RoomInfoMapper roomInfoMapper;

    /**
     * 查询订单信息
     * 
     * @param orderId 订单信息ID
     * @return 订单信息
     */
    @Override
    public OrderInfo selectOrderInfoById(Long orderId)
    {
        return orderInfoMapper.selectOrderInfoById(orderId);
    }

    /**
     * 查询订单信息列表
     * 
     * @param orderInfo 订单信息
     * @return 订单信息
     */
    @Override
    public List<OrderInfo> selectOrderInfoList(OrderInfo orderInfo)
    {

        return orderInfoMapper.selectOrderInfoList(orderInfo);
    }

    /**
     * 新增订单信息
     * 
     * @param orderInfo 订单信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertOrderInfo(OrderInfo orderInfo)
    {

        orderInfo.setCreateTime(DateUtils.getNowDate());
        orderInfoMapper.insertOrderInfo(orderInfo);
        List<OrderInfo> list=orderInfoMapper.selectOrderInfoList(orderInfo);
        roomInfoMapper.updateRoomStatusByIds(orderInfo.getRooms(), (long) 1,Long.toString(list.get(0).getOrderId()));
        return 1;
    }

    /**
     * 修改订单信息
     * 
     * @param orderInfo 订单信息
     * @return 结果
     */
    @Override
    public int updateOrderInfo(OrderInfo orderInfo)
    {
        orderInfo.setUpdateTime(DateUtils.getNowDate());
        return orderInfoMapper.updateOrderInfo(orderInfo);
    }

    /**
     * 删除订单信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteOrderInfoByIds(String ids)
    {
        return orderInfoMapper.deleteOrderInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除订单信息信息
     * 
     * @param orderId 订单信息ID
     * @return 结果
     */
    @Override
    public int deleteOrderInfoById(Long orderId)
    {
        return orderInfoMapper.deleteOrderInfoById(orderId);
    }
}
